home *** CD-ROM | disk | FTP | other *** search
- /*
- * the class LINE_ELEMENT
- * Copyright (C) 1996, 1997 Kazutaka Hirata <khirata@jove.acs.unt.edu>
- */
-
- #include "../common/bool.h"
-
- #include "../kbandef.h"
-
- #include "lineelem.h"
-
- #define outside(x, y, z) (((y) <= (x)) || ((z) <= (y)))
-
- void LINE_ELEMENT::save_200a8(FILE_NEW& fp) const
- {
- fp.printf("%d %d %d %d %d\n",
- ac_s().x(),
- ac_s().y(),
- ac_e().x(),
- ac_e().y(),
- width()
- );
- }
-
- int LINE_ELEMENT::load_170_core(const char *str)
- {
- XYT x1, y1, x2, y2;
- uint width;
- sscanf(str, "%d %d %d %d %d", &x1, &y1, &x2, &y2, &width);
- x1 = x1 * 25400 / 300;
- y1 = y1 * 25400 / 300;
- x2 = x2 * 25400 / 300;
- y2 = y2 * 25400 / 300;
- width = width * 25400 / 1000;
- set_ac_s(XY(x1, y1));
- set_ac_e(XY(x2, y2));
- set_width(width);
- return true;
- }
-
- int LINE_ELEMENT::load_primitive_170(const char *str)
- {
- load_170_core(str);
- set_ac_s(XY(ac_s().x(), Y_V1TOV2 - ac_s().y()));
- set_ac_e(XY(ac_e().x(), Y_V1TOV2 - ac_e().y()));
- return true;
- }
-
- int LINE_ELEMENT::load_component_170(const char *str)
- {
- load_170_core(str);
- set_ac_s(XY(ac_s().x(), - ac_s().y()));
- set_ac_e(XY(ac_e().x(), - ac_e().y()));
- return true;
- }
-
- int LINE_ELEMENT::unit_change_micron2kban(int micron)
- {
- return micron * DIS_MICRON;
- }
-
- void LINE_ELEMENT::load_200a8(const char* str)
- {
- XYT x1, y1, x2, y2;
- uint width;
- sscanf(str, "%d %d %d %d %d", &x1, &y1, &x2, &y2, &width);
- x1 = unit_change_micron2kban(x1);
- y1 = unit_change_micron2kban(y1);
- x2 = unit_change_micron2kban(x2);
- y2 = unit_change_micron2kban(y2);
- width = unit_change_micron2kban(width);
- XY ac1(x1, y1);
- XY ac2(x2, y2);
- set_ac_s(ac1);
- set_ac_e(ac2);
- set_width(width);
- }
-
- int LINE_ELEMENT::is_on_line(XYT eps, const XY& ac)
- {
- int result;
-
- uint w = maximum(width(), uint(eps));
- if(is_holizontal()) {
- XY p(ac_s().x(), ac_s().y() - w / 2);
- XY q(ac_e().x(), ac_s().y() + w / 2);
- result = ac.is_in_box(p, q);
- } else if(is_vertical()) {
- XY p(ac_s().x() - w / 2, ac_s().y());
- XY q(ac_s().x() + w / 2, ac_e().y());
- result = ac.is_in_box(p, q);
- } else {
- XY ac_o, ac_p;
- if(ac_s().y() < ac_e().y()) {
- ac_o = ac_s();
- ac_p = ac_e();
- } else {
- ac_o = ac_e();
- ac_p = ac_s();
- }
- double rad = - ac_o.get_radian(ac_p);
- XY ac_s_moved = ac_s() - ac;
- XY ac_e_moved = ac_e() - ac;
- ac_s_moved.rotate(ac_s_moved, rad);
- ac_e_moved.rotate(ac_e_moved, rad);
- XY ac_origin(0, 0);
- XY p(ac_s_moved.x(), ac_s_moved.y() - w / 2);
- XY q(ac_e_moved.x(), ac_s_moved.y() + w / 2);
- result = ac_origin.is_in_box(p, q);
- }
- return result;
- }
-
- void LINE_ELEMENT::rotate_90()
- {
- m_ac_s.rotate_90();
- m_ac_e.rotate_90();
- }
-